<template>
  <view class="body">
    <view class="name titleBold">{{ info.name }}</view>
    <view v-if="info.tips" class="tips"> {{ info.tips }} </view>
    <view class="sickList">
      <view
        v-for="item in info.options"
        :key="item.id"
        :class="[info.rowBlock === true ? 'sickBox blocks' : 'sickBox']"
      >
        <view :class="[checkValue === item.id ? 'sickSpan cur' : 'sickSpan']" @click="choseList(info, item)">
          {{ item.name }}
          <span v-if="checkValue === item.id" class="curImg"><img :src="curIcon" /></span>
        </view>
        <view v-if="item.tips" class="kidTips">{{ item.tips }}</view>
      </view>
    </view>
    <view v-if="checkValue === 30">
      <view class="inputBox">
        <span class="name lineHeight86">戒烟</span>
        <input
          id="quitSmokingYear"
          v-model="mainData.quitSmokingYear"
          type="digit"
          class="uni-input lineHeight86"
          name="height"
          placeholder-class="phcolor"
          @change="inputChange($event)"
        />
        <view class="unit">年</view>
        <view class="clear"></view>
      </view>
      <view class="inputBox">
        <span class="name lineHeight86">之前抽烟</span>
        <input
          id="preSmokingYear"
          v-model="mainData.preSmokingYear"
          type="digit"
          class="uni-input lineHeight86"
          name="preSmokingYear"
          placeholder-class="phcolor"
          @change="inputChange($event)"
        />
        <view class="unit">年</view>
        <view class="clear"></view>
      </view>
      <view class="inputBox">
        <span class="name lineHeight86">每天</span>
        <input
          id="height"
          v-model="mainData.preSmokingBags"
          type="digit"
          class="uni-input lineHeight86"
          name="height"
          placeholder-class="phcolor"
          @change="inputChange($event)"
        />
        <view class="unit">包</view>
        <view class="clear"></view>
      </view>
    </view>
    <view v-if="checkValue === 40">
      <view class="inputBox">
        <span class="name lineHeight86">抽烟</span>
        <input
          id="smokingYear"
          v-model="mainData.smokingYear"
          type="digit"
          class="uni-input lineHeight86"
          name="height"
          placeholder-class="phcolor"
          @change="inputChange($event)"
        />
        <view class="unit">年</view>
        <view class="clear"></view>
      </view>
      <view class="inputBox">
        <span class="name lineHeight86">每天</span>
        <input
          id="smokingBags"
          v-model="mainData.smokingBags"
          type="digit"
          class="uni-input lineHeight86"
          name="height"
          placeholder-class="phcolor"
          @change="inputChange($event)"
        />
        <view class="unit">包</view>
        <view class="clear"></view>
      </view>
    </view>
  </view>
</template>

<script>
import { checkBetweenDecimalOne } from '@/common/assessKeyCheck';
// import { ajaxSend } from './ajaxHealth.js';
import curIcon from '@/static/icon/cur.png';
export default {
  props: {
    // 是否展示搜索按钮
    info: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      checkValue: undefined,
      curIcon: curIcon,
      noChose: false,
      mainData: {
        quitSmokingYear: '',
        preSmokingYear: '',
        preSmokingBags: '',
        smokingYear: '',
        smokingBags: ''
      }
    };
  },
  computed: {
    active() {
      return this.$store.getters.active;
    },
    assessForm() {
      return this.$store.getters.assessForm;
    }
  },
  mounted() {},
  methods: {
    // eslint-disable-next-line complexity
    validate() {
      // 疾病直接提交接口
      let submitData = this.assessForm;
      submitData[this.info.key] = this.checkValue;
      if (!this.checkValue && this.checkValue !== 0) {
        uni.showToast({ title: `请选择${this.info.name}`, icon: 'none' });
        return false;
      }
      if (this.checkValue === 30) {
        this.mainData.smokingYear = '';
        this.mainData.smokingBags = '';
      } else if (this.checkValue === 40) {
        this.mainData.quitSmokingYear = '';
        this.mainData.preSmokingYear = '';
        this.mainData.preSmokingBags = '';
      } else {
        this.mainData.smokingYear = '';
        this.mainData.smokingBags = '';
        this.mainData.quitSmokingYear = '';
        this.mainData.preSmokingYear = '';
        this.mainData.preSmokingBags = '';
      }
      if (this.checkValue === 30 && !this.mainData.quitSmokingYear) {
        uni.showToast({ title: `请输入戒烟年数`, icon: 'none' });
        return false;
      }
      if (this.checkValue === 30 && !this.mainData.preSmokingYear) {
        uni.showToast({ title: `请输入之前抽烟年数`, icon: 'none' });
        return false;
      }
      if (this.checkValue === 30 && !this.mainData.preSmokingBags) {
        uni.showToast({ title: `请输入每日吸烟量`, icon: 'none' });
        return false;
      }
      if (this.checkValue === 40 && !this.mainData.smokingYear) {
        uni.showToast({ title: `请输入抽烟年数`, icon: 'none' });
        return false;
      }
      if (this.checkValue === 40 && !this.mainData.smokingBags) {
        uni.showToast({ title: `请输入每日吸烟量`, icon: 'none' });
        return false;
      }
      if (checkBetweenDecimalOne(this.mainData.quitSmokingYear, '戒烟几年', 1, 100)) {
        uni.showToast({ title: `戒烟几年数据错误，请重新输入`, icon: 'none' });
        return false;
      }
      if (checkBetweenDecimalOne(this.mainData.preSmokingYear, '已经抽烟几年', 1, 100)) {
        uni.showToast({
          title: `之前抽烟几年数据错误，请重新输入`,
          icon: 'none'
        });
        return false;
      }
      if (checkBetweenDecimalOne(this.mainData.preSmokingBags, '每天抽烟几包', 0.1, 10)) {
        uni.showToast({ title: `每日吸烟量错误，请重新输入`, icon: 'none' });
        return false;
      }
      if (checkBetweenDecimalOne(this.mainData.smokingYear, '抽烟几年', 1, 100)) {
        uni.showToast({ title: `抽烟几年数据错误，请重新输入`, icon: 'none' });
        return false;
      }
      if (checkBetweenDecimalOne(this.mainData.smokingBags, '每天抽几包', 0.1, 10)) {
        uni.showToast({ title: `每日吸烟量错误，请重新输入`, icon: 'none' });
        return false;
      }
      return Object.assign(this.mainData, { smok: this.checkValue });
      // Object.keys(this.mainData).forEach((key) => {
      //   submitData[key] = this.mainData[key];
      // });
      // 获取健康指标指导意见 判断是出健康提示还是直接下一步 start
      // const healthData = await ajaxSend(Object.assign(this.mainData, { smok: this.checkValue }));
      // let curActive = this.active + 1;
      // if (healthData && healthData.length > 0) {
      //   // 如果有异常，则提示
      //   this.$store.commit('assessQuestion/SET_AJAXRESMESSAGE', healthData); // 存提示信息到vux，数组格式
      //   this.$store.commit('assessQuestion/SET_AJAXRES', true); // 开启提示
      // } else {
      //   this.$store.commit('assessQuestion/SET_ACTIVE', curActive);
      //   this.$store.commit('assessQuestion/SET_AJAXRES', false);
      // }
      // // 获取健康指标指导意见 判断是出健康提示还是直接下一步 end
      // this.$store.commit('assessQuestion/SET_ASSESSFORM', submitData);
    },
    proBtn() {
      let curActive = this.active - 1;
      this.$store.commit('assessQuestion/SET_ACTIVE', curActive);
    },
    choseList(info, val) {
      this.checkValue = val.id;
      this.$emit('choseList', info.key, this.validate);
    },
    inputChange(e) {}
  }
};
</script>
<style lang="scss" scoped>
.body {
  padding: 24rpx;
  margin-bottom: 30rpx;
}
$black: rgba(0, 0, 0, 0.55);
.sickList {
  .sickBox {
    display: inline-block;
    width: 50%;
    .sickSpan {
      display: inline-block;
      text-align: center;
      width: 80%;
      padding: 10rpx 18rpx;
      margin: 12rpx 16rpx;
      border: 2rpx solid rgba(178, 178, 178, 1);
      border-radius: 16rpx;
      font-size: 28rpx;
      position: relative;
      .curImg {
        position: absolute;
        width: 40rpx;
        height: 40rpx;
        right: 0;
        bottom: 0;
        border: none;
        img {
          width: 40rpx;
          height: 40rpx;
        }
      }
    }
    .cur {
      border: 2rpx solid rgba(242, 85, 89, 1);
      color: rgba(242, 85, 89, 1);
    }
    .kidTips {
      color: $black;
      font-size: 28rpx;
      margin-bottom: 30rpx;
    }
  }
  .blocks {
    display: block;
    width: 100%;
    .sickSpan {
      width: 590rpx;
    }
  }
  .blocksInl {
    display: inline-block;
    width: auto;
    .sickSpan {
      width: auto;
    }
  }
}
.inputBox {
  position: relative;
  padding: 20rpx 0;
  .title {
    float: left;
  }
  .name {
    float: left;
    width: 140rpx;
    color: $black;
  }
  .uni-input {
    float: right;
    text-align: right;
    margin-right: 40rpx;
    width: 186rpx;
    padding: 0 12rpx;
    background: rgba(244, 244, 244, 1);
  }
  .unit {
    position: absolute;
    right: 0;
    top: 30rpx !important;
    color: $black;
    font-size: 28rpx;
  }
}
.inputdisplay {
  margin: 6rpx;
  .displayInput {
    .uni-textarea {
      border: 1px solid #eee;
      border-radius: 16rpx;
      width: 100%;
      padding: 10rpx 20rpx;
      height: 84rpx;
      width: 590rpx;
      font-size: 28rpx;
    }
  }
}
</style>
